function saveClade( params ) {
    
    Shadowbox.open( { content: "",
                      player: "html",
                      title: "Save Clade for Grafting",
                      height: $(window).height() * .25,
                      width: $(window).width() * .25,
                      options: {
                          onFinish: function() { addSaveCladeContent( { id: params.id } ); } } } );
}

function addSaveCladeContent( params ) {

    $('#sb-player').append(
        makeEl('div').attr( { 'class': 'topMargin1' } ).append(
            makeEl('div').attr( { 'class': 'width30 right fLeft rightMargin1' } ).text( 'Name : ' ),
            makeEl('div').attr( { 'class': 'width60 fLeft' } ).append( makeEl('input').attr( { 'id': 'cladeName' } ) ),
            makeEl('div').attr( { 'class': 'clear' } ) ),
        makeEl('div').attr( { 'class': 'topMargin1' } ).append(
            makeEl('div').attr( { 'class': 'width30 right fLeft rightMargin1' } ).text( 'Comment : ' ),
            makeEl('div').attr( { 'class': 'width60 fLeft' } ).append( makeEl('input').attr( { 'id': 'cladeComment' } ) ),
            makeEl('div').attr( { 'class': 'clear' } ) ),
        makeEl('div').attr( { 'class': 'right width90' } ).append(
                makeEl('a').attr( { 'class': 'rightMargin1',
                                    'href': 'javascript:void(0);' } ).text('Save').click( function() { postSaveClade( { id: params.id } ); } ),
                makeEl('a').attr( { 'href': 'javascript:void(0);' } ).text('Cancel').click( function() { Shadowbox.close(); } ) ) );
}

function postSaveClade( params ) {

    $.ajax( { url: '/' + globals.applicationName + '/default/saveClade',
              type: "POST",
              data: { nodeId: params.id, treeId: globals.treeId, name: $('#cladeName').val(), comment: $('#cladeComment').val() },
              success: function() { },
              error: function() { alert('Failed to Save Clade'); } } );

    Shadowbox.close();
}
